include("shared.lua")
include("derma.lua")

function kontrolMenu()
	MAIN_FRAME = vgui.Create("KFrame")
	MAIN_FRAME:SetSize(600, 400)
	MAIN_FRAME:SetPos(ScrW() / 2 - 300, ScrH() / 2 - 200)
	MAIN_FRAME:SetTitle("kontrol - Administration in Moderation")
	MAIN_FRAME:SetDraggable(true)
	MAIN_FRAME:SetSizable(false)
	MAIN_FRAME:ShowCloseButton(true)
	
	local banlistBut = vgui.Create("KButton", MAIN_FRAME)
	banlistBut:SetSize(100, 20)
	banlistBut:SetPos(200, 30)
	banlistBut:SetText("Ban List")
	banlistBut.DoClick = function()
		RunConsoleCommand("sv_kontrol_unbanmenu")
	end
	
	MAIN_PLAYERLIST = vgui.Create("DComboBox", MAIN_FRAME)
	MAIN_PLAYERLIST:SetPos(10, 30)
	MAIN_PLAYERLIST:SetSize(180, 360)
	MAIN_PLAYERLIST:SetMultiple(false)
	for k,v in pairs(player.GetAll()) do
		MAIN_PLAYERLIST:AddItem(v:Name())
		MAIN_PLAYERLIST:GetItems()[k].UniqueID = v:UniqueID()
	end
	
	local refreshBut = vgui.Create("DButton", MAIN_FRAME)
	refreshBut:SetPos(169, 369)
	refreshBut:SetSize(16, 16)
	refreshBut:SetText("")
	refreshBut.DoClick = function()
		RefreshPlayerlist()
	end
	refreshBut.Paint = function()
		surface.SetMaterial(Material("gui/silkicons/magnifier"))
		surface.SetDrawColor(255, 255, 255, 255)
		surface.DrawTexturedRect(0, 0, 16, 16)
	end
	
	local actionList = vgui.Create("DPanelList", MAIN_FRAME)
	actionList:SetPos(200, 60)
	actionList:SetSize(390, 330)
	actionList:SetPadding(5)
	actionList:SetSpacing(5)
	actionList:EnableHorizontal(false)
	actionList:EnableVerticalScrollbar(true)
	actionList.Paint = function()
		draw.RoundedBox(0, 0, 0, 390, 330, Color(0, 0, 0, 255))
		draw.RoundedBox(0, 1, 1, 388, 328, Color(180, 180, 180, 255))
	end
	
	local colors = {}
	local key = 1
	colors[1] = Color(70, 70, 70, 255)
	colors[2] = Color(60, 60, 60, 255)
	for k,v in pairs(plugins) do
		if key == 1 then key = 2 elseif key == 2 then key = 1 end
		
		local but = vgui.Create("KListButton")
		but:SetSize(380, 25)
		but:SetText(k)
		but.DoClick = function()
			if #MAIN_PLAYERLIST:GetSelectedItems() > 0 then
				RunConsoleCommand(v, MAIN_PLAYERLIST:GetSelectedItems()[1].UniqueID)
			end
		end
		
		actionList:AddItem(but)
	end
	
	MAIN_FRAME:MakePopup()
end

function RefreshPlayerlist()
	if MAIN_PLAYERLIST then
		MAIN_PLAYERLIST:Clear()
		
		for k,v in pairs(player.GetAll()) do
			MAIN_PLAYERLIST:AddItem(v:Name())
			MAIN_PLAYERLIST:GetItems()[k].UniqueID = v:UniqueID()
		end
	end
end